<?php
/**
* feedback相关逻辑
*
* @author     Robot
* @version    1.0
* @package    Base Framework
* @access     public
* @copyright  商业软件,受著作权保护
* @link       http://***
*/
class postModule extends Base
{
	/**
	 * 构造函数
	 *
	 */
	public function __construct(){}

	/**
	* 按照模板整理post过来的数据
	*
	* @access public
	* @param  void
	* @return void
	*/
	public function fillTemplate($arr)
	{
		$tpl = VarData::$CFArgs;

		$tpl['tebieyaoqiu'] = $this->value(1, $arr['tebieyaoqiu']);
		$tpl['gongzuohuanjing'] = $this->value(2, $arr['gongzuohuanjing']);
		$tpl['gongzuochangsuo'] = $this->value(3, $arr['gongzuochangsuo']);
		$tpl['xitongyali'] = array(
			"zuigaoyali"=>$arr['xitongyali_zuigaoyali'],
			"edingyali"=>$arr['xitongyali_edingyali']
			);
		$tpl['zhubengleixing'] = $this->value(5, $arr['zhubengleixing']);
		$tpl["liuliangliusu"] = array(
			"zhubengzuidaliulang"=>$arr['liuliangliusu_zhubengzuidaliulang'],
			"xitongzuidaliusu"=>$arr['liuliangliusu_xitongzuidaliusu'],
			"youxiangrongji"=>$arr['liuliangliusu_youxiangrongji']
			);
		$tpl["huanjingwendu"] = array(
			"zuigao"=>$arr['huanjingwendu_zuigao'],
			"zuidi"=>$arr['huanjingwendu_zuidi']
			);
		$tpl["gongzuowendu"] = array(
			"zuigao"=>$arr['gongzuowendu_zuigao'],
			"zuidi"=>$arr['gongzuowendu_zuidi']
			);
		$tpl['fazuleixing'] = $this->value(9, $arr['fazuleixing']);
		$tpl['zhixingyuanjian'] = $arr['zhixingyuanjian'];
		$tpl['yuanjianqingkuang'] = $this->value(11, $arr['yuanjianqingkuang']);
		$tpl['runhuayaoqiu'] = $this->value(12, $arr['runhuayaoqiu']);
		$tpl['jiechujiezhi'] = $this->value(13, $arr['jiechujiezhi']);

		return $tpl;
	}

	/**
	* 封装值
	*
	* @access public
	* @param  void
	* @return void
	*/
	private function value($key, $v)
	{
		if(!$v)
		{
			$T[] = 0;
		}
		else if(is_array($v))
		{
			foreach($v as $m)
			{
				$T[] = $key."_". $m;
			}
		}
		else
		{
			$T[] = $key."_". $v;
		}

		return join(",", $T);
	}

	/**
	* 检查参数
	*
	* @access public
	* @param  void
	* @return void
	*/
	public function checkPost($arr)
	{
		return true;
	}

	/**
	* 查询符合条件的油
	*
	* @access public
	* @param  void
	* @return void
	*/
	public function getResult($arr)
	{
		################
		### 特别要求 ###
		################
		$tmp = explode("_", $arr['tebieyaoqiu']);
		//无毒=v1
		if($tmp[1] == 1){
			$F["f1"] = 1;

		//环保可降解=V2
		}else if($tmp[1] == 2){
			$F["f2"] = 1;
		}

		################
		### 工作环境 ###
		################
		$tmp = explode("_", $arr['gongzuohuanjing']);
		//湿度高=V4+V25
		if($tmp[1] == 1){
			$F["f4+f25"] = 1;

		//粉尘大=V25
		}else if($tmp[1] == 2){
			$F["f25"] = 1;

		//明火或300度以上高温表面=V3
		}else if($tmp[1] == 3){
			$F["f3"] = 1;
		}

		################
		### 工作场所 ###
		################
		$tmp = explode("_", $arr['gongzuochangsuo']);
		//室内=V25
		if($tmp[1] == 1){
			$F["f25"] = 0;

		//室外=V25
		}else if($tmp[1] == 2){
			$F["f25"] = 1;

		//室内外=V25
		}else if($tmp[1] == 3){
			$F["f25"] = 1;
		}

		################
		### 系统压力 ###
		################
		//最高压力 <=7MPa=V6；>=7MPa=v7+v8
		if($arr['xitongyali']['zuigaoyali'] <= 7){
			$F["f6"] = 1;
		}else if($arr['xitongyali']['zuigaoyali'] <= 16){
			$F["f7"] = 1;
		}else{
			$F["f8"] = 1;
		}

		//额定压力 <=7MPa=V6；>=7MPa=v7+v8
		if($arr['xitongyali']['edingyali'] < 7){
			$F["f6"] = 1;
		}else{
			$F["f7_f8"] = 1;
		}

		################
		### 主泵类型 ###
		################
		$tmp = explode("_", $arr['zhubengleixing']);
		//叶片泵=V7+V8
		if($tmp[1] == 1){
			$F["f7_f8"] = 1;

		//柱塞泵=V26
		}else if($tmp[1] == 2){
			$F["f26"] = 1;

		//齿轮泵=V6+V7
		}else if($tmp[1] == 3){
			$F["f6_f7"] = 1;

		//螺杆泵=V6
		}else if($tmp[1] == 4){
			$F["f6"] = 1;
		}

		################
		### 流量流速 ###
		################
		//主泵最大流量=V25+V28
		if($arr['liuliangliusu']['zhubengzuidaliulang']){
			$F["f25_f28"] = 1;
		}
		
		//系统最大流速=V25+V27
		if($arr['liuliangliusu']['xitongzuidaliusu']){
			$F["f25_f27"] = 1;
		}

		//油箱容积=v25
		if($arr['liuliangliusu']['youxiangrongji']){
			$F["f25"] = 1;
		}

		################
		### 环境温度 ###
		################
		//最高= v25,限定 0~50摄氏度之间
		if($arr['huanjingwendu']['zuigao'] >= 0 && $arr['huanjingwendu']['zuigao'] <= 50){
			$F["f25"] = 1;
		}else{
			$r['ret'] = -1;
			$r['result'] = "环境温度：最高温度限定 0~50℃之间";
			return $r;
		}

		//最低 -30以下=V9+V10；-30~-10=V10+V11；-10以上=V11,限定-50~20摄氏度之间
		if($arr['huanjingwendu']['zuidi'] < -50 || $arr['huanjingwendu']['zuidi'] > 30){
			$r['ret'] = -1;
			$r['result'] = "环境温度：最低温度限定 -50~30℃之间";
			return $r;
		}
		if($arr['huanjingwendu']['zuidi'] < -30){
			$F["f9_f10"] = 1;

		}else if($arr['huanjingwendu']['zuidi'] < -10){
			$F["f10_f11"] = 1;

		}else{
			$F["f11"] = 1;
		}

		################
		### 工作温度 ###
		################
		//最高 85以上 =V12;  85以下=V11,限定 -30~120摄氏度之间
		if($arr['gongzuowendu']['zuigao'] > 120 || $arr['gongzuowendu']['zuigao'] < -30){
			$r['ret'] = -1;
			$r['result'] = "工作温度：最低温度限定 -30~120℃之间";
			return $r;
		}
		if($arr['gongzuowendu']['zuigao'] > 85){
			$F["f12"] = 1;
		}else{
			$F["f11"] = 1;
		}

		//最低 -25以下=V9；-25~ -10=V10；-10以上=V11,限定-50~20摄氏度之间
		if($arr['gongzuowendu']['zuidi'] < -30 || $arr['gongzuowendu']['zuidi'] > 50){
			$r['ret'] = -1;
			$r['result'] = "工作温度：最低温度限定 -30~50℃之间";
			return $r;
		}
		if($arr['gongzuowendu']['zuidi'] < -25){
			$F["f9"] = 1;

		}else if($arr['gongzuowendu']['zuidi'] < -10){
			$F["f10"] = 1;

		}else{
			$F["f11"] = 1;
		}

		//最高-最低 >=50，=V13 ;  （内部计算项）
		if($arr['gongzuowendu']['zuigao'] - $arr['gongzuowendu']['zuidi'] >= 50){
			$F["f13"] = 1;
		}

		################
		### 阀组类型 ###
		################
		$tmp = explode("_", $arr['fazuleixing']);
		//有伺服阀=V18+V19+V20
		if($tmp[1] == 1){
			$F["f18_f19_f20"] = 1;

		//有比例阀=V16+V17+V18
		}else if($tmp[1] == 2){
			$F["f16_f17_f18"] = 1;
		}

		################
		### 执行元件 ###
		################
		//线速度=V9+V10+V11+V12
		if($arr['zhixingyuanjian']){
			$F["f9_f10_f11_f12"] = 1;
		}

		################
		### 元件情况 ###
		################
		$tmp = explode("_", $arr['yuanjianqingkuang']);
		//含铜=V26
		if($tmp[1] == 1){
			$F["f26"] = 1;

		//含银=V26
		}else if($tmp[1] == 2){
			$F["f26"] = 1;
		}

		################
		### 润滑要求 ###
		################
		$tmp = explode("_", $arr['runhuayaoqiu']);
		//与导轨=V14
		if($tmp[1] == 1){
			$F["f14"] = 1;

		//与齿轮=V15
		}else if($tmp[1] == 2){
			$F["f15"] = 1;
		}

		################
		### 接触介质 ###
		################
		$tmp = explode("_", $arr['jiechujiezhi']);
		//有腐蚀=V25+V27 
		if($tmp[1] == 1){
			$F["f25_f27"] = 1;

		//无腐蚀=V25+V28
		}else if($tmp[1] == 2){
			$F["f25_f28"] = 1;
		}

		//整理sql条件
		$aKey = array();
		foreach($F as $key => $val)
		{
			$aTmpKey = array();
			if(strpos($key, "+"))
			{
				$tmp_key = explode("+", $key);
				foreach($tmp_key as $k)
				{
					$aTmpKey[] = $k."=1";
				}
				$SQL[] = "(".join(" AND ", $aTmpKey).")";
			}
			else
			{
				$tmp_key = explode("_", $key);
				foreach($tmp_key as $k)
				{
					$aTmpKey[] = $k."=1";
				}
			}
			if(count($aTmpKey) > 1)
			{
				$SQL[] = "(".join(" OR ", $aTmpKey).")";
			}else{
				$SQL[] = $aTmpKey[0];
			}
		}
		$SQL[] = "state=1";
		$r['sql'] = join(" AND ", $SQL);

		//拼sql
		$sql = "SELECT id, name, pinpai
			FROM product_library
			WHERE ". join(" AND ", $SQL);

		$oDmo = new DMO_Product_Library();
		$oDmo->setField("id,name,pinpai");
		$aRes = $oDmo->getAllWithSql($sql);

		if(count($aRes) < 1)
		{
			$r['ret'] = 0;
			$r['result'] = "很抱歉，没找到您所需要的油品。";
			return $r;
		}
		else if(count($aRes) > 12)
		{
			$r['ret'] = 0;
			$r['result'] = "你提供的信息太少，不能选出合适油品，请重填。调试信息#####结果数".count($aRes);

			return $r;
		}
		else
		{
			$tmp = array();
			foreach($aRes as $val)
			{
				$tmp[] = $val['pinpai'].$val['name'];
			}

			$r['ret'] = 1;
			$r['result'] = $tmp;
		}

		return $r;
	}

	public function checkFirstPost($data)
	{
		if($data["normal_c"]==7){
			return -1;
		}
		if($data["max_c"]==8){
			return -1;
		}
		foreach ($data["work_huanjing"] as  $value) {
			if( in_array($value, array("I","J","K"))){
				return -1;
			}
		}
		
		if($data["runhuajileibie"]==3){
			return -1;
		}
		if($data["changjiapinpai"]==5){
			return -1;
		}
		if($data["lengquezhi"]==7){
			return -1;
		}
		if($data["niandudengji"]=="B"){
			return -1;
		}
		if($data["runhuayongtu"]=="F"){
			return -2;
		}
		return 1;
	}
	public function checkFourPost($data)
	{
		if(in_array($post["tesuyaoqiu"], array("B","C","D","E"))){
			return -1;
		}
		if(in_array($post["jiechujiezhi"], array("F","K"))){
			return -1;
		}

		if($post["runhuafangshi"]=="A"){
			return -1;
		}
		if($post["hbs"]>0&&$post["hrc"]>0){
			return -1;
		}
		if($post["runhuasudu"]==10){
			return -1;
		}
		return 1;
	}
	public function checkThreePost($post)
	{
		if($post["yuanxiansudu"]>=25){
			return -1;
		}
		if($post["runhuafangshi"]=="A"){
			return -1;
		}
		if(in_array($post["tesuyaoqiu"], array("B","C","D","E"))){
			return -1;
		}
		if(in_array($post["jiechujiezhi"], array("F","K"))){
			return -1;
		}
		return 1;
	}
	public function checkOnePost($post)
	{
		$val = max($post["max_yali"],$post["min_yali"]);
		if($val>40){
			return -1;
		}
		if($post["zhixingyuanjian"]>25){
			return -1;
		}
		return 1;
	}

	public function findResult($session,$post,$type){
		$where = array();
		//第一页数据拼接
		$normal_c_arr = array(1=>"aa0=1",2=>"aa1=1",3=>"aa2=1",4=>"aa3=1",5=>"aa4=1",6=>"aa5=1");
		if(!$session["lengquezhi"]){
			$where[] = $normal_c_arr[$session["normal_c"]];
		}

		$min_c_arr = array(1=>"ab1=1",2=>"ab2=1",3=>"ab3=1",4=>"ab4=1",5=>"ab5=1",6=>"ab6=1");
		if(!$session["jiarezhi"]){
			$where[] = $min_c_arr[$session["min_c"]];
		}

		$max_c_arr = array(1=>"ac0=1",2=>"ac1=1",3=>"ac2=1",4=>"ac3=1",5=>"ac4=1",6=>"ac5=1",7=>"ac6=1",8=>"ac7=1");
		if(!$session["lengquezhi"]){
			$where[] = $max_c_arr[$session["max_c"]];
		}

		$work_huanjing_arr = array("B"=>"(bg1=1 or bg2=1 or bg3=1)","H"=>"(ba1=1 or ba2=1 or ba3=1)","D"=>"(bf1=1 or bf2=1 or bf3=1)","E"=>"(aa2=1 or aa3=1 or aa4=1 or aa5=1 or aa6=1)","C"=>"(ba1=1 or ba2=1 or ba3=1)");
		foreach ($session["work_huanjing"] as $value) {
			$where[] = $work_huanjing_arr[$value];
		}
		
		$runhuajileibie_arr = array(1=>"(ae1=1 or c11=1 or c12=1 or c13=1)",2=>"(ae2=1 or af1=1)");
		$where[] = $runhuajileibie_arr[$session["runhuajileibie"]];

		$changjiapinpai_arr = array(1=>"z1=1",2=>"z2=1",3=>"z3=1",4=>"z4=1");
		$where[] = $changjiapinpai_arr[$session["changjiapinpai"]];	


		$jiarezhi_arr = array(1=>"ab3=1",2=>"ab2=1",3=>"ab1=1",4=>"ab1=1",5=>"ab1=1");
		$where[] = $jiarezhi_arr[$session["jiarezhi"]];	

		$lengquezhi_arr = array(1=>"aa0=1",2=>"aa1=1",3=>"aa2=1",4=>"aa3=1",5=>"aa4=1",6=>"aa5=1");
		$where[] = $lengquezhi_arr[$session["lengquezhi"]];	

		$anquanyaoqiu_arr = array(1=>"af1=1",2=>"af2=1");
		$where[] = $anquanyaoqiu_arr[$session["anquanyaoqiu"]];

		if($session["huanbaoyaoqiu"]==1){
			$where[] = "af2=1";
		}

		if($session["runhuaji"]==1||$session["runhuaji"]==2){
			$where[] = "(ag3=1 or ag2=1 or ag1=1)";
		}

		$ayou_arr =array(1=>"a1=1"  ,2=>"a2=1" ,3=>"a3=1" ,4=>"a4=1" ,5=>"a5=1" ,6=>"a6=1"  ,7=>"a7=1" ,8=>"a8=1" ,9=>" a9=1" ,10=>" a10=1"  ,11=>"a11=1"  ,12=>"a12=1");
		$where[] = $ayou_arr[$session["ayou"]];

		$kangmoyaoqiu_arr = array(1=>"(ah2=1 or ah3=1 or ah4=1 or ah5=1 or ah6=1)",2=>"(ah1=1 or ah2=1 or ah3=1)",3=>"(ah3=1 or ah4=1 or ah5=1 or ah6=1 )",4=>"(ah1=1 or ah2=1 or ah3=1 or ah4=1 or ah5=1 or ah6=1)");
		$where[] = $kangmoyaoqiu_arr[$session["kangmoyaoqiu"]];

		$qingjiedu_arr = array(1=>"ai1=1",2=>"(ai1=1 or ai2=1)",3=>"(ai3=1 or ai2=1)",4=>"(ai3=1 or ai2=1 or ai4=1)",5=>"(ai3=1 or ai5=1 or ai4=1)",6=>"(ai6=1 or ai5=1 or ai4=1)",7=>"(ai6=1 or ai5=1 or ai4=1 or ai7=1)");
		$where[] = $qingjiedu_arr[$session["qingjiedu"]];

		$max_arr =array(1=>"aa0=1"  ,2=>"aa0=1" ,3=>"aa1=1" ,4=>"aa2=1" ,5=>"aa2=1" ,6=>"aa2=1"  ,7=>"aa3=1" ,8=>"aa3=1" ,9=>" aa4=1" ,10=>" aa4=1"  ,11=>"aa5=1");
		if(!$session["lengquezhi"]){
			$where[] = $max_arr[$session["max"]];
		}

		$min_arr =array(1=>"ab1=1"  ,2=>"ab1=1" ,3=>"ab1=1" ,4=>"ab2=1" ,5=>"ab3=1" ,6=>"ab4=1"  ,7=>"ab5=1" ,8=>"ab6=1" );
		if(!$session["jiarezhi"]){
			$where[] = $min_arr[$session["min"]];
		}

		$runhuayongtu_arr =array("A"=>"(ae2=1 or af1=1)"  ,"B"=>"(ae1=1 or c11=1 or c12=1 or c13=1)" ,"D"=>"ai7=1","E"=>"ai7=1");
		$where[] = $runhuayongtu_arr[$session["runhuayongtu"]];

		switch ($type) {
			case 1:
				if($post["anquanyaoqiu"]=="A"||$post["anquanyaoqiu"]=="B"){
					$where[] = "af1=1";
				}else{
					$where[] = "ae2=1";
				}
				if(is_numeric($post["max_yali"])||is_numeric($post["min_yali"])){
					$val = max($post["max_yali"],$post["min_yali"]);
					if($val<=7){
						$where[] = "(b13=1 or b14=1 or b15=1 or b16=1 or b18=1)";
					}else if($val<=14){
						$where[] = "(b14=1 or b15=1 or b16=1 or b18=1)";
					}else if($val<=21){
						$where[] = "(b15=1 or b16=1 or b18=1)";
					}else if($val<=32){
						$where[] = "(b16=1 or b18=1)";
					}else if($val<=40){
						$where[] = "b18=1";
					}
				}

				$zhugongleixing_arr =array("A"=>"(b7=1 or b8=1 or b9=1)","B"=>"b12=1","C"=>"(b10=1 or b11=1)","D"=>"(b26=1 or b27=1)");
				$where[] = $zhugongleixing_arr[$post["zhugongleixing"]];

				$fazhuleixing_arr =array("A"=>"(b1=1 or b2=1 or b3=1)","B"=>"(b4=1 or b5=1 or b6=1)");
				$where[] = $fazhuleixing_arr[$post["fazhuleixing"]];

				if($post["yuanjianqingkuang"]=="A"||$post["yuanjianqingkuang"]=="B"){
					$where[] = "b12=1";
				}

				$runhuayongqiu_arr =array("A"=>"(b22=1 or b23=1)","B"=>"(b19=1 or b20=1 or b21=1)");
				$where[] = $runhuayongqiu_arr[$post["runhuayongqiu"]];

				$xitongyaoqiu_arr =array("A"=>"b24=1","B"=>"(b14=1 or b15=1 or b16=1 or b18=1)","C"=>"b25=1","D"=>"(ab4=1 or ab5=1 or ab6=1)","E"=>"(aa3=1 or aa4=1 or aa5=1 or aa6=1)");
				$where[] = $xitongyaoqiu_arr[$post["xitongyaoqiu"]];

				if($post["gongzuozhuangtai"]=="D"){
					$where[] = "(b15=1 or b16=1 or b18=1)";
				}

				$order = " order by A3 desc,A2 desc,A4 desc,A5 desc,A1  desc,ah1 desc,ah2 desc,ah3 desc,ah4 desc,ah5 desc,ah6 desc,x1 desc,x2 desc,x3 desc,x4 desc,x5 desc";
				break;
			case 2:
				return -1;
				break;
			case 3:
				$cixing_arr =array("A"=>"(c1=1 or c2=1 or c3=1)","B"=>"(c4=1 or c5=1 or c6=1)","C"=>"(c4=1 or c5=1 or c6=1)","D"=>"(c1=1 or c2=1 or c3=1)","E"=>"(c4=1 or c5=1 or c6=1)","F"=>"c10=1","G"=>"(c11=1 or c12=1)");
				foreach ($post["cixing"] as $value) {
					$where[] = $cixing_arr[$value];
				}

				$chuandongfangshi_arr =array("A"=>"c13=1","B"=>"c13=1","C"=>"(ae1=1 or c11=1 or c12=1)");
				$where[] = $chuandongfangshi_arr[$post["chuandongfangshi"]];

				if(is_numeric($post["chuandongbi"])){
					if($post["chuandongbi"]<=8){
						$where[] = "c14=1 ";
					}else if($post["chuandongbi"]>8){
						$where[] = "c15=1 ";
					}
				}
				if(is_numeric($post["chuandonggonglu"])){
					if($post["chuandonggonglu"]<=1.1){
						$where[] = "(ah1=1 or ah2=1 or ah3=1)";
					}else if($post["chuandonggonglu"]<=220){
						$where[] = "(ah3=1 or ah4=1 or ah5=1)";
					}else if($post["chuandonggonglu"]>220){
						$where[] = "(ah4=1 or ah5=1 or ah6=1)";
					}
				}

				$ciluncaizhi_arr =array("A"=>"(ah1=1 or ah2=1 or ah3=1)","B"=>"(ah1=1 or ah2=1 or ah3=1)","C"=>"(ah1=1 or ah2=1 or ah3=1)","H"=>"b12=1");
				$where[] = $ciluncaizhi_arr[$post["ciluncaizhi"]];

				$cilunfuhe_arr =array("A"=>"(ah1=1 or ah2=1 or ah3=1)","B"=>"(ah3=1 or ah4=1 or ah5=1)","C"=>"(ah4=1 or ah5=1 or ah6=1)");
				$where[] = $cilunfuhe_arr[$post["cilunfuhe"]];
				
				if(is_numeric($post["cilunmoshu"])){
					if($post["cilunmoshu"]>8){
						$where[] = "(ah4=1 or ah5=1 or ah6=1)";
					}
				}

				if(is_numeric($post["jiechuyingli"])){
					if($post["jiechuyingli"]>1100){
						$where[] = "(ah4=1 or ah5=1 or ah6=1)";
					}else if($post["jiechuyingli"]<=1100){
						$where[] = "(ah3=1 or ah4=1 or ah5=1)";
					}else if($post["jiechuyingli"]<=500){
						$where[] = "(ah1=1 or ah2=1 or ah3=1)";
					}
				}

				$hbs_arr =array(1=>"(ah1=1 or ah2=1 or ah3=1)",2=>"(ah3=1 or ah4=1)",3=>"(ah4=1 or ah5=1)",4=>"(ah5=1 or ah6=1)",5=>"ah6=1");
				if(array_key_exists($post["hbs"], $hbs_arr)){
					$where[] = $hbs_arr[$post["hbs"]];
				}

				$hrc_arr =array(1=>"(ah1=1 or ah2=1 or ah3=1)",2=>"(ah3=1 or ah4=1)",3=>"(ah4=1 or ah5=1)",4=>"(ah5=1 or ah6=1)",5=>"ah6=1");
				if(array_key_exists($post["hrc"], $hrc_arr)){
					$where[] = $hrc_arr[$post["hrc"]];
				}

				if(is_numeric($post["yuanxiansudu"])){
					if($post["yuanxiansudu"]<=0.5){
						$where[] = "a8=1";
					}else if($post["yuanxiansudu"]<=0.1){
						$where[] = "a9=1";
					}else if($post["yuanxiansudu"]<=5){
						$where[] = "a7=1";
					}else if($post["yuanxiansudu"]<=12.5){
						$where[] = "a6=1";
					}else if($post["yuanxiansudu"]<=16){
						$where[] = "a5=1";
					}else if($post["yuanxiansudu"]<=25){
						$where[] = "a4=1";
					}
				}

				$runhuafangshi_arr =array("C"=>"(a4=1 or a5=1 or a6=1 or a7=1)","D"=>"(a5=1 or a6=1 or a7=1 or a8=1 or a9=1)");
				$where[] = $runhuafangshi_arr[$post["runhuafangshi"]];

				$yundongzhuangkuang_arr =array("B"=>"c29=1","C"=>"c30=1");
				$where[] = $yundongzhuangkuang_arr[$post["yundongzhuangkuang"]];

				if($post["tesuyaoqiu"]=="A"){
					$where[] = "b25=1";
				}

				$jiechujiezhi_arr =array("A"=>"(bg1=1 or bg2=1 or bg3=1)","B"=>"(ba1=1 or ba2=1 or ba3=1)","C"=>"(ab4=1 or ab5=1 or ab6=1)","D"=>"(aa3=1 or aa4=1 or aa5=1 or aa6=1)","E"=>"(ba1=1 or ba2=1 or ba3=1)","L"=>"(c29=1 or c30=1)");
				$where[] = $jiechujiezhi_arr[$post["jiechujiezhi"]];

				$order = " order by A7 desc,A8 desc,A6 desc,A9 desc,A5 desc,A10 desc,A4 desc,A11 desc,A3 desc,A12 desc,x1 desc,x2 desc,x3 desc,x4 desc,x5 desc,ah1 desc,ah2 desc,ah3 desc,ah4 desc,ah5 desc,ah6 desc";
				break;
			case 4:
				return -1;
				break;
			case 5:
				$hbs_arr =array(1=>"(ah2=1 or ah3=1)",2=>"(ah3=1 or ah4=1)",3=>"(ah4=1 or ah5=1)",4=>"(ah5=1 or ah6=1)",5=>"ah6=1");
				if(array_key_exists($post["hbs"], $hbs_arr)){
					$where[] = $hbs_arr[$post["hbs"]];
				}

				$hrc_arr =array(1=>"(ah2=1 or ah3=1)",2=>"(ah3=1 or ah4=1)",3=>"(ah4=1 or ah5=1)",4=>"(ah5=1 or ah6=1)",5=>"ah6=1");
				if(array_key_exists($post["hrc"], $hrc_arr)){
					$where[] = $hrc_arr[$post["hrc"]];
				}

				$runhuasudu_arr =array(1=>"(a6=1 or a7=1)",2=>"(a6=1 or a7=1)",3=>"(a5=1 or a6=1 )",4=>"(a5=1 or a6=1)",5=>"(a5=1 or a6=1)",6=>"(a5=1 or a6=1)",7=>"(a3=1 or a4=1)",8=>"(a3=1 or a4=1)",9=>"(a2=1 or a3=1)");
				$where[] = $runhuasudu_arr[$post["runhuasudu"]];

				$jiechuleixing_arr =array("B"=>"(ah2=1 or ah3=1 or ah4=1)","A"=>"(ah3=1 or ah4=1 or ah5=1 or ah6=1)");
				$where[] = $jiechuleixing_arr[$post["jiechuleixing"]];

				$yundongxingshi_arr =array("A"=>"(ah2=1 or ah3=1 or ah4=1)","C"=>"(ah3=1 or ah4=1 or ah5=1 or ah6=1)");
				$where[] = $yundongxingshi_arr[$post["yundongxingshi"]];

				if($post["yundongfangxiang"]=="B"||$post["yundongfangxiang"]=="C"){
					$where[] = "(ak1=1 or ak2=1 or ak3=1 or a5=1 or a6=1 or a7=1 or a8=1 or a9=1)";
				}

				if($post["yundongfangshi"]=="B"||$post["yundongfangshi"]=="C"){
					$where[] = "(b14=1 or b15=1 or b16=1 or b18=1)";
				}

				if($post["runhuabuwei"]=="A"||$post["runhuabuwei"]=="B"){
					$where[] = "b12=1";
				}

				$runhuafangshi_arr =array("C"=>"(a2=1 or a3=1 or a4=1 or a5=1 or a6=1)","D"=>"(a3=1 or a4=1 or a5=1 or a6=1 or a7=1)");
				$where[] = $runhuafangshi_arr[$post["runhuafangshi"]];

				$buweifanghu_arr =array("A"=>"c13=1","B"=>"c13=1","C"=>"(ae1=1 or c11=1 or c12=1)");
				$where[] = $buweifanghu_arr[$post["buweifanghu"]];

				$yundongqingkuang_arr =array("B"=>"c29=1","C"=>"c30=1");
				$where[] = $yundongqingkuang_arr[$post["yundongqingkuang"]];

				$zhendongqingkuang_arr =array("B"=>"c29=1","C"=>"c30=1");
				$where[] = $zhendongqingkuang_arr[$post["zhendongqingkuang"]];

				$buweichengzai_arr =array("A"=>"(ah2=1 or ah3=1 or ah1=1)","B"=>"(ah3=1 or ah4=1 or ah5=1)","C"=>"(ah4=1 or ah5=1 or ah6=1)");
				$where[] = $buweichengzai_arr[$post["buweichengzai"]];

				$jiechujiezhi_arr =array("A"=>"(bg1=1 or bg2=1 or bg3=1)","B"=>"(ba1=1 or ba2=1 or ba3=1)","C"=>"(ab4=1 or ab5=1 or ab6=1)","D"=>"(aa3=1 or aa4=1 or aa5=1 or aa6=1)","E"=>"(ba1=1 or ba2=1 or ba3=1)","L"=>"(c29=1 or c30=1)");
				$where[] = $jiechujiezhi_arr[$post["jiechujiezhi"]];

				if($post["tesuyaoqiu"]=="A"){
					$where[] = "b25=1";
				}

				$buweicaizhi_arr =array("A"=>"(ah2=1 or ah3=1 or ah1=1)","B"=>"(ah2=1 or ah3=1 or ah1=1)");
				$where[] = $buweicaizhi_arr[$post["buweicaizhi"]];

				$mochaleixing_arr =array("A"=>"(ah2=1 or ah3=1 or ah1=1)","B"=>"(ah4=1 or ah5=1 or ah6=1)","C"=>"(ah4=1 or ah5=1 or ah6=1)");
				$where[] = $mochaleixing_arr[$post["mochaleixing"]]; 

				// $order = "  order by A6 desc,A7 desc,A5 desc,A8 desc,A4 desc,A9 desc,A3 desc,A10 desc,A2 desc,A11 desc,A1 desc,A12 desc,x1 desc,x2 desc,x3 desc,x4 desc,x5 desc,ah1 desc,ah2 desc,ah3 desc,ah4 desc,ah5 desc,ah6 desc";
				$order = "  order by A3 desc,A2 desc,A4 desc,A5 desc,A1  desc,ah1 desc,ah2 desc,ah3 desc,ah4 desc,ah5 desc,ah6 desc,x1 desc,x2 desc,x3 desc,x4 desc,x5 desc";

				break;
			case 6:
				return -1;
				break;
			default:
				# code...
				break;
		}
		//过滤空值
		$where = array_filter($where);

		//$where[] = "state=1";
		$r['sql'] = join(" AND ", $where);
		$r['sql'] .= $order;
		//拼sql
		$sql = "SELECT id, name, pinpai
			FROM product_library
			WHERE ". join(" AND ", $where);

		$oDmo = new DMO_Product_Library();
		$oDmo->setField("id,name,pinpai");
		$ret = $oDmo->getAllWithSql($sql,$order);

		if(count($ret) < 1){
			$r['ret'] = 0;
			$r['result'] = "很抱歉，没找到您所需要的油品。";
			return $r;
		}else if(count($ret) <= 5&&count($ret)>=1){
			$tmp = array();
			foreach($ret as $val)
			{
				$tmp[] = $val['pinpai'].$val['name'];
			}
			$r['ret'] = 1;
			$r['result'] = $tmp;
		}
		else if(count($ret) > 5&&count($ret) < 80){
			$tmp = array();
			foreach($ret as $key=>$val)
			{
				$tmp[] = $val['pinpai'].$val['name'];
				if($key>=4){
					break;
				}
			}
			$r['ret'] = 2;
			$r['result'] = $tmp;
		}else{
			$r['ret'] = 0;
			$r['result'] = "你提供的信息太少或不准确，不能选出合适油品，请重填。调试信息#####结果数".count($ret);
			return $r;
		}
		return $r;
	}

}

?>